import config from 'config'
import httpFetch from 'share/httpFetch'
import errorMessage from 'share/errorMessage';

export default {
  //得到日期列表
  getDateList(){
    return httpFetch.get(`${config.baseUrl}/api/pcfp/date`)
  },

  //判断里程补贴计价模式
  isLadder(){
    //9001代表单价模式 9002阶梯计价模式
    return  httpFetch.get(`${config.baseUrl}/api/pcfp/mode`)
  },

  //获取预生成费用信息
  getPrePaymentInfo(date,isCreateFee){
    if(isCreateFee){
      return httpFetch.get(`${config.baseUrl}/api/pcfp/invoice/data?date=${date}`)
    }else{
      return httpFetch.get(`${config.baseUrl}/api/pcfp/web/invoice?date=${date}`)
    }
  },

  //添加订单
  addOrders(params){
    return httpFetch.post(`${config.baseUrl}/api/pcfp/order`,params)
  },

  //获取订单
  getOrders(params) {
    return httpFetch.get(`${config.baseUrl}/api/pcfp/order`, params)
      .catch(err => {
        errorMessage(err.response);
      });
  },

  //删除订单
  deleteOrder(id){
    return httpFetch.get(`${config.baseUrl}/api/pcfp/delete/order?ids=${id}`)
  },

  //编辑订单
  updateOrder(params){
    return httpFetch.post(`${config.baseUrl}/api/pcfp/order`,params)
  },

  //调用腾讯API得到导航距离
  getDistance(params) {
    return httpFetch.get(`${config.baseUrl}/ws/direction/v1/driving/`, params);
  },

  //生成费用
  generateCost(params){
    return httpFetch.post(`${config.baseUrl}/api/pcfp/invoice/v2`,params)
  },

  //生成费用获取费用信息
  getCostInfo(date){
    return httpFetch.get(`${config.baseUrl}/api/pcfp/invoice/data?date=${date}`)
  },

  //判断是否有没有规则
  isHaveRule(){
    return httpFetch.get(`${config.baseUrl}/api/pcfp/step/rules`)
  },

  //获取里程补贴费用详情
  getFeeDetail(invoiceOID, params = {}){
    return httpFetch.get(`${config.baseUrl}/api/invoices/${invoiceOID}`, params)
  },

  // 获取里程补贴详情
  getMileageDetails(params) {
    return httpFetch.post(`/api/pcfp/detail`,params)
      .catch(err => {
        errorMessage(err.response);
        throw err
      });
  },

  // 获取高德轨迹
  getAmapTrack(params) {
    return httpFetch.get('/api/pcfp/track/search', params)
  }
}
